package com.peng.controller;

import com.github.pagehelper.PageInfo;
import com.peng.Repo.PageStatic;
import com.peng.servier.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AdminUserController {
    @Autowired
    private UserService userService;

    @GetMapping("/userList")
    public PageInfo getUser(@RequestParam(name = "username", defaultValue = "") String username,
                            @RequestParam(name = "status", defaultValue = "0") Integer status,
                            @RequestParam(name = "Level", defaultValue = "0") Integer Level,
                            @RequestParam(name = "page", defaultValue = PageStatic.page) Integer page,
                            @RequestParam(name = "size", defaultValue = PageStatic.size) Integer size) {
        System.out.println("username"+username);
        System.out.println("status"+status);
        System.out.println("Level"+Level);
        System.out.println("page"+page);
        System.out.println("size"+size);
        return userService.selectAll(username, status, Level, page, size);
    }

    @GetMapping("/deleteUser")
    public boolean deleteUser(@Nullable @RequestParam("id") Integer... id) {
        return userService.deleteUserById(id);
    }

    @GetMapping("/updateUser")
    public boolean updateUserStatus(@RequestParam(name = "status", defaultValue = "1") int status,
                                    @RequestParam(name = "id") Integer... id) {
        return userService.updateUserByStatus(status, id);
    }

}
